<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch"
             label-width="98px">
      <el-form-item label="姓名" prop="userName">
        <el-input v-model="queryParams.userName" placeholder="请输入姓名" clearable size="small"
                  @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="证件号" prop="zjh">
        <el-input v-model="queryParams.zjh" placeholder="请输入证件号" clearable size="small"
                  @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="合格率大于" prop="hglGt">
        <el-input v-model="queryParams.hglGt" type="number" placeholder="请输入合格率" clearable size="small"
                  @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="合格率小于" prop="hglLt">
        <el-input v-model="queryParams.hglLt" type="number" placeholder="请输入合格率" clearable size="small"
                  @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="平均分大于" prop="avgGt">
        <el-input v-model="queryParams.avgGt" type="number" placeholder="请输入平均分" clearable size="small"
                  @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="平均分小于" prop="avgLt">
        <el-input v-model="queryParams.avgLt" type="number" placeholder="请输入平均分" clearable size="small"
                  @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="warning" icon="el-icon-search" size="mini" @click="handleQuery">搜索
        </el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="ksfxList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center">
        <template slot-scope="scope">
          <div>
            {{scope.$index+1}}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="姓名" align="center" prop="userName" />
      <el-table-column label="证件号" align="center" prop="zjh" />
      <el-table-column label="人员类别" align="center" prop="category" :formatter="categoryFormat" />
      <el-table-column label="合格率" align="center" prop="hgl">
        <template slot-scope="scope">
          <div>
            {{scope.row.hgl*100}}%
          </div>
        </template>
      </el-table-column>
      <el-table-column label="平均分" align="center" prop="avg" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="handleDetail(scope.row)"  v-hasPermi="['qb:examAna:xqList']">
            查看明细</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize" @pagination="getList" />

    <!-- 添加或修改人员信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" append-to-body :close-on-click-modal='false'>
      <el-table v-loading="loading1" :data="ksfxMxList">
        <el-table-column type="selection" width="55" align="center">
          <template slot-scope="scope">
            <div>
              {{scope.$index+1}}
            </div>
          </template>
        </el-table-column>
        <el-table-column label="分数" align="center" prop="score" />
        <el-table-column label="时间" align="center" prop="createTime" />
      </el-table>
      <pagination v-show="total>0" :total="total" :page.sync="queryParams1.pageNum"
                  :limit.sync="queryParams1.pageSize" @pagination="getList1" />
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">关闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { ksfxList, ksfxMxList } from "@/api/ksfx/ksfx";

export default {
  name: "User",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: false,
      loading1: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      total1: 0,
      // 人员信息表格数据
      ksfxList: [],
      ksfxMxList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        zjh: null,
        userName: null,
        zjh: null,
        hglGt: null,
        hglLt: null,
        avgGt: null,
        avgLt: null,
      },
      queryParams1: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        category: null
      },
    };
  },
  created() {
    this.getList();
    this.getDicts("bus_rylb").then(response => {
      this.categoryOptions = response.data;
    });
  },
  methods: {
    // 人员类别字典翻译
    categoryFormat(row, column) {
      return this.selectDictLabel(this.categoryOptions, row.category);
    },
    handleDetail(row) {
      this.queryParams1.category = row.category
      this.queryParams1.userId = row.userId
      this.open = true
      this.getList1()
    },
    /** 查询人员信息列表 */
    getList() {
      this.loading = true;
      let obj = { ...this.queryParams }
      if (obj.hglGt) {
        obj.hglGt = obj.hglGt / 100
      }
      if (obj.hglLt) {
        obj.hglLt = obj.hglLt / 100
      }
      ksfxList(obj).then(response => {
        this.ksfxList = response.rows
        this.total = response.total;
        this.loading = false;
      });
    },
    getList1() {
      this.loading1 = true;
      ksfxMxList(this.queryParams1).then(response => {
        this.ksfxMxList = response.rows;
        this.total1 = response.total;
      }).finally(() => {
        this.loading1 = false;
      })
    },
    // 取消按钮
    cancel() {
      this.open = false;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
  }
};
</script>

<style lang="scss" >
input::-webkit-outer-spin-button, input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    appearance: none;
    margin: 0;
}

/* 火狐 */
input{
  -moz-appearance:textfield;
}
</style>
